import datetime
import os
import pytest
from loguru import logger
from const import PATH, CASE_DIR


def get_report_path():
    report_path=PATH/'reports'
    report_path.mkdir(exist_ok=True)

    time_smap = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")

    task_dir = report_path / f'{time_smap}'
    task_dir.mkdir()

    log_path = task_dir / 'log'
    log_path.mkdir()

    log_file = log_path / 'pytest.log'
    logger.add(log_file)

    data_dir = task_dir/ 'data'
    html_dir = task_dir/ 'html'

    return data_dir, html_dir
def main():
    allure_dir,html_dir=get_report_path()
    pytest.main(['-sv', str(CASE_DIR), '--alluredir', str(allure_dir)])
    # 生成报告
    os.system(f'allure generate {allure_dir} -o {html_dir} --single-file')
    # 打包推送报告
    # jenkins
if __name__ == '__main__':
    main()